package cn.wolfcode.controller;


import cn.wolfcode.domain.JsonResult;
import cn.wolfcode.domain.MessageReply;
import cn.wolfcode.service.IMessageReplyService;
import cn.wolfcode.qo.QueryObject;

import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/messageReply")
public class MessageReplyController {

    @Autowired
    private IMessageReplyService messageReplyService;

    @RequiredPermission(name="留言回复显示",expression ="messageReply:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<MessageReply> pageInfo = messageReplyService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "messageReply/list";
    }

    @RequestMapping("/delete")
    @RequiredPermission(name="留言回复删除",expression ="messageReply:delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null) {
            messageReplyService.delete(id);
        }
        return new JsonResult();
    }


    @RequestMapping("/save")
    @RequiredPermission(name="留言回复保存",expression ="messageReply:save")
    @ResponseBody
    public JsonResult saveOrUpdate(MessageReply messageReply){
        messageReplyService.save(messageReply);
        return new JsonResult();
    }

}
